package academic.concordia.bankofquebec.entity;

import java.io.Serializable;
import java.util.List;


import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name="CLIENT")
public class Client implements Serializable {
	
	private static final long serialVersionUID = 1L;
	private String idNumber;
	private String name;
	private String address;
	private String telephone;
	private String password;
	//@OneToMany(mappedBy="account")
	private List<BankAccount> products;
	//@OneToMany(mappedBy="bill")
	private List<Bill> bills;
	//@OneToOne(mappedBy="identificationType")
	private IdentificationType identificationType;

	@Id
	public String getIdNumber() {
		return idNumber;
	}

	public void setIdNumber(String idNumber) {
		this.idNumber = idNumber;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@Fetch(FetchMode.SELECT)
	public List<BankAccount> getProducts() {
		return products;
	}

	public void setProducts(List<BankAccount> products) {
		this.products = products;
	}
	
	public void addProduct(BankAccount product){
		this.products.add(product);
	}

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@Fetch(FetchMode.SELECT)
	public List<Bill> getBills() {
		return bills;
	}

	public void setBills(List<Bill> bills) {
		this.bills = bills;
	}

	@Enumerated(EnumType.STRING)
	public IdentificationType getIdentificationType() {
		return identificationType;
	}

	public void setIdentificationType(IdentificationType identificationType) {
		this.identificationType = identificationType;
	}
	
	public BankAccount getProduct(String type){
		BankAccount product = null;
		for (int i=0; i<products.size(); i++){
			product = products.get(i);
			if (product.getType().equals(type))
				return product;
		}
		return product;
	}
	
	public boolean hasProduct(String type){
		for (int i=0; i<products.size(); i++){
			if (products.get(i).getType().equals(type))
				return true;
		}
		return false;
	}
}
